package hk.cic.cwrs.bio.integration;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Locale;

public class BioProService extends Service {
    private static final String TAG = "BioProService";
     private Context mContext;
    private IBioTemplateService.Stub stub = new IBioTemplateService.Stub(){

        @Override
        public String RequestTemplate(String sessionId) throws RemoteException {
            return null;
        }

        @Override
        public int setTemplateMode(int templateMode) throws RemoteException {
            return 0;
        }

        @Override
        public String VerifyTemplate(String sessionId, String CWRNo, String template, String writeDate, String writerId, String SerialNo, String greenCardExpire) throws RemoteException {

            //发消息去拍照和定位
                 Log.e("client",sessionId);

                 Intent intent = new Intent(mContext, MainActivity.class);
                 intent .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 mContext.startActivity(intent);



                 //发消息





            JSONObject json = new JSONObject();
            try {
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
                json.put("SessionID", sessionId);
                json.put("CWRNo", CWRNo);
                json.put("Result", 1);
                json.put("Datetime", df.format(System.currentTimeMillis()));
                return json.toString();
            }catch(Exception e){
                e.printStackTrace();

                return json.toString();
            }





        }

        @Override
        public String getLogPath(int logType) throws RemoteException {
            return null;
        }

        @Override
        public String getParameter(String key, int mParaType) throws RemoteException {
            return null;
        }

        @Override
        public int setParameter(String key, int mParaType, String value) throws RemoteException {
            return 0;
        }

        @Override
        public void upgradeService() throws RemoteException {

        }
    };


    public BioProService() {
        this.mContext=this;
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
       return  stub;
    }
}
